package com.cskaoyan.dbutills.resultset.impl;

import com.cskaoyan.bean.Account;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 创建日期: 2022/10/11 14:49
 *
 * @author ciggar
 */
public class MyResultSetHandler implements ResultSetHandler {
    @Override
    public List<Account> handle(ResultSet resultSet) throws SQLException {

        ArrayList<Account> accounts = new ArrayList<>();

        while (resultSet.next()) {

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int money = resultSet.getInt("money");

            Account account = new Account();

            account.setId(id);
            account.setName(name);
            account.setMoney(money);

            accounts.add(account);

        }

        return accounts;
    }
}
